import axios from "axios";
import { apiDev, apiProd } from '@/config/url';


// 创建axios实例
const service = axios.create({
  baseURL: apiDev, // 基础URL从环境变量读取
  timeout: 10000, // 请求超时时间
});

// GET请求
export const get = (url, params) => {
  return service.get(url, { params });
};

// POST请求
export const post = (url, data) => {
  return service.post(url, data);
};

// PUT请求
export const put = (url, data) => {
  return service.put(url, data);
};

// DELETE请求
export const del = (url, params) => {
  return service.delete(url, { params });
};

// 文件上传请求
export const upload = (url, file) => {
  const formData = new FormData();
  formData.append('file', file);
  return service.post(url, formData, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });
};

export default service;